//
//  HWMyInformationVIew.m
//  嗨文
//
//  Created by 响当当 on 2019/1/11.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWMyInformationVIew.h"
#import "HWMeHeadView.h"
#import "HWMyInformationCell.h"
#import "HWMyNoticeViewController.h"
#import "HWCommentViewController.h"
#import "HWHelpViewController.h"
#import "HWFeedBackViewController.h"
#import "HWAboutBookViewController.h"
#import "HWReadHabitViweController.h"
#import "HWMyWalletViewController.h"
#import "HWReadRecordController.h"
#import "HWBookReadViewController.h"
#import "HWReadHabitResetViewController.h"
#import "HWMoneyWebViewController.h"

@interface HWMyInformationVIew ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)HWMeHeadView *headView;
@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, strong)NSArray *functionArr;
@end

@implementation HWMyInformationVIew

- (NSArray *)functionArr
{
    if (!_functionArr)
    {
        _functionArr = [[NSArray alloc]init];
    }
    return _functionArr;
}

- (HWMeHeadView *)headView
{
    if (!_headView)
    {
        _headView = [[HWMeHeadView alloc]initWithFrame:CGRectMake(0,NAVIBAR_HEIGHT,SCREEN_WIDTH,262*kUIScaleBasePlus)];
        if (/* DISABLES CODE */ (1))
        {
            [_headView setHeight:262*kUIScaleBasePlus];
        }
        else
        {
            [_headView setHeight:318*kUIScaleBasePlus];
        }
        WeakSelf(self)
        [_headView setGotoFunctionBlock:^(NSInteger tag) {
            [weakSelf gotoRechargeOrGetMoney:tag];
        }];
    }
    return _headView;
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = 0;
        _tableView.tableHeaderView = self.headView;
    }
    return _tableView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addSubview:self.tableView];
    }
    return self;
}

#pragma mark - tableview Delegate datasource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.functionArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 64*kUIScaleBasePlus;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HWMyInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"hwMyinformationCell"];
    if (!cell)
    {
        cell = [[HWMyInformationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"hwMyinformationCell"];
        cell.selectionStyle = 0;
        
    }
    
    if ([current_User.isHideinfo.stringValue isEqualToString:@"0"])
    {
        if (indexPath.row > 2)
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else
        {
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
   
    
    [cell getInfo:self.functionArr[indexPath.row] indexPathRow:indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([current_User.isHideinfo.stringValue isEqualToString:@"0"])
    {
        switch (indexPath.row)
        {
            case 0:
            {
                //            AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
                //            [appDelegate gotoBookEarn];
                HWMoneyWebViewController *vc = [[HWMoneyWebViewController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
                break;
            case 1:
            {
                [HWUtilties pushWebWithUrl:@"http://www.haishuwu.com/bookTokenTask" title:@"签到" toUrl:@"/bookTokenTask" toId:@"263ffef75c5c90cd"];
            }
                break;
            case 2:
            {
                [HWUtilties pushWebWithUrl:@"http://www.haishuwu.com/updateAgent" title:@"升级代理" toUrl:@"/updateAgent" toId:@"fe2763cb3af29aa6"];
            }
                break;
            case 3:
            {
                DISMISS_SVP(1.0f);
                [SVProgressHUD showInfoWithStatus:@"暂未开放"];
                DISMISS_SVP(1.0f);
            }
                break;
            case 4:
            {
                HWMyNoticeViewController *vc = [[HWMyNoticeViewController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
                break;
            case 5:
            {
                HWCommentViewController *vc = [[HWCommentViewController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
                break;
            case 6:
            {
                DISMISS_SVP(1.0f);
                [SVProgressHUD showInfoWithStatus:@"暂未开放"];
                DISMISS_SVP(1.0f);
            }
                break;
            case 7:
            {
                HWAboutBookViewController *vc = [[HWAboutBookViewController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
                break;
            case 8:
            {
                HWFeedBackViewController *vc = [[HWFeedBackViewController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
                break;
            case 9:
            {
                //            HWHelpViewController *vc = [[HWHelpViewController alloc]init];
                //            vc.hidesBottomBarWhenPushed = YES;
                //            [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
                [HWUtilties pushWebWithUrl:@"http://www.haishuwu.com/helpCenter" title:@"帮助中心" toUrl:@"/helpCenter" toId:@"2fe1dfe2f9045de6"];
            }
                break;
            case 10:
            {
                NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"0512-66627482"];
                UIWebView * callWebview = [[UIWebView alloc] init];
                [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
                [self addSubview:callWebview];
                
            }
                break;
        }
    }
    else
    {
        switch (indexPath.row)
        {
            case 0:
            {
                HWMyNoticeViewController *vc = [[HWMyNoticeViewController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
                break;
            case 1:
            {
                HWCommentViewController *vc = [[HWCommentViewController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
                break;
            case 2:
            {
                DISMISS_SVP(1.0f);
                [SVProgressHUD showInfoWithStatus:@"暂未开放"];
                DISMISS_SVP(1.0f);
            }
                break;
            case 3:
            {
                HWAboutBookViewController *vc = [[HWAboutBookViewController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
                break;
            case 4:
            {
                HWFeedBackViewController *vc = [[HWFeedBackViewController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
                break;
            case 5:
            {
                //            HWHelpViewController *vc = [[HWHelpViewController alloc]init];
                //            vc.hidesBottomBarWhenPushed = YES;
                //            [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
                [HWUtilties pushWebWithUrl:@"http://www.haishuwu.com/helpCenter" title:@"帮助中心" toUrl:@"/helpCenter" toId:@"2fe1dfe2f9045de6"];
            }
                break;
            case 6:
            {
                NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"0512-66627482"];
                UIWebView * callWebview = [[UIWebView alloc] init];
                [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
                [self addSubview:callWebview];
            }
                break;
        }
    }
}

#pragma mark - 获取数据
- (void)getMyInformation:(HWMyinformationModel *)model
{
    if ([current_User.isHideinfo.stringValue isEqualToString:@"0"])
    {
        self.functionArr = @[@{@"icon":@"read_taste",@"title":@"邀请好友",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"give_ticket",@"title":@"每日送1000嗨书卷",@"subTitle":@"邀请好友得大量书卷",@"level":@""},
                             @{@"icon":@"upgrade_agent",@"title":@"升级代理（嗨赚10万元）",@"subTitle":@"做代理，赚更多",@"level":@""},
                             @{@"icon":@"task_money",@"title":@"任务赚钱",@"subTitle":@"做任务赚金币，可在钱包中提现",@"level":@"Lv32"},
                             @{@"icon":@"my_message",@"title":@"我的消息",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"my_comment",@"title":@"我的评论",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"contribute_author",@"title":@"我是作者",@"subTitle":@"我要投稿名利双收",@"level":@""},
                             @{@"icon":@"about_hi",@"title":@"关于嗨小说",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"view_feedback",@"title":@"意见反馈",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"help_center",@"title":@"帮助中心",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"customer_service",@"title":@"客服中心",@"subTitle":@"",@"level":@""}];
    }
    else
    {
        self.functionArr = @[@{@"icon":@"my_message",@"title":@"我的消息",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"my_comment",@"title":@"我的评论",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"contribute_author",@"title":@"我是作者",@"subTitle":@"我要投稿名利双收",@"level":@""},
                             @{@"icon":@"about_hi",@"title":@"关于嗨小说",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"view_feedback",@"title":@"意见反馈",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"help_center",@"title":@"帮助中心",@"subTitle":@"",@"level":@""},
                             @{@"icon":@"customer_service",@"title":@"客服中心",@"subTitle":@"",@"level":@""}];
    }
    
    
    [self.headView getMyinformationDate:model];

    [self.tableView reloadData];
}

#pragma mark - 跳转充值 提现等
- (void)gotoRechargeOrGetMoney:(NSInteger)tag
{
    switch (tag)
    {
        case 0:
        {
            AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
            [appDelegate gotoBookShelf];
        }
            break;
        case 1:
        {
            HWReadRecordController *vc = [[HWReadRecordController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            NSString *str = [kUserDefaults objectForKey:@"habbit"];
            if ([str isEqualToString:@"1"])
            {
                HWReadHabitViweController *vc = [[HWReadHabitViweController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
            else
            {
                HWReadHabitResetViewController *vc = [[HWReadHabitResetViewController alloc]init];
                vc.hidesBottomBarWhenPushed = YES;
                [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
            }
           
        }
            break;
        case 3:
        {
            HWMyWalletViewController *vc = [[HWMyWalletViewController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
       
        }
            break;
            
        default:
            break;
    }
}


@end
